﻿<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />
    <link href="../css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <script src="../js/jquery-1.11.1.min.js" type="text/javascript"></script>
    <script src="../../Scripts/commen_js/jquery.cookie.min.js"></script>
    <script src="../../Scripts/commen_js/json2.js"></script>
    <script src="../js/MJ_JSComment_two.js"></script>
    <script type="text/javascript">
        
        $(document).ready(function () {
            $("#tip").hide();
            var code = GetQueryString("code");
            poststr = "{\"type\":\"getopenid\",\"code\":\"" + code + "\"}";
            mj_js_ajax("json", poststr, getopenid);
        })
        function getopenid(data) {
            if (data.result == "ok") {
                $.cookie("openid", data.msg);
                checkuser(data.msg);
            }
        }


        function checkuser(openid) {
            poststr = "{\"type\":\"checkuser\",\"code\":\"" + openid + "\"}";
            mj_js_ajax("json", poststr, showresult);
        }
        function showresult(data) {
            if (data.result == "have") {
                $("#tip").css("display", "block")
            }
            else { }
        }
        function GetQueryString(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return unescape(r[2]); return null;
        }
        function Submit() {

            if (document.getElementById("tip").style.display == "block") {
                alert("你的手机已经绑定无需重复绑定！");
                return;

            }

            var area = $.trim(document.getElementById("area").value);
            var building = $.trim($("#building").val());
            var dorm = $.trim($("#dorm").val());
            var phone = $.trim($("#phone").val());
            if (isUndefinedNullOrEmpty(area) && isUndefinedNullOrEmpty(building)&&isUndefinedNullOrEmpty(dorm)) {
                alert("区域或楼号或宿舍号不能为空");
                return false;
            }
            else if (checkphoneformat(phone)) {
                var data = area + "|" + building + "|" + dorm + "|" + phone+"|"+$.cookie("openid");
                poststr = "{\"type\":\"bind_username\",\"bind_data\":\"" + data + "\"}";
                mj_js_ajax("json", poststr, offerstate);

            }
            else {
                alert("请输入正确的手机号码");
                return false;
            }

        }
        function offerstate(data) {
            if (data.result == "ok") {
                alert(data.msg);
            }
            else { alert(data.msg); }
        }
        function checkphoneformat(phone) {

            var result = true;
            if (/^.{11}$/.test(phone)) {
                var p = new RegExp("1[3|4|5|7|8|][0-9]{9}");
                result = p.test(phone);
            }
            else if (/^.{6}$/.test(phone)) {
                var p = new RegExp("[0-9]{6}");
                result = p.test(phone);
            }
            else {
                result = false;
            }
            return result;
        }
        </script>
    <title>绑定</title>
</head>
<body>
    <div class="container-fluid">
        <h3 class="text-center text-info">
            邑大水行<br />
            用户微信绑定</h3>
        <hr />
          <div id="tip" style="margin-top:-13px;margin-bottom:10px;text-align:center;color:red; display:none">手机已经绑定无需重新绑定</div>
        <form class="form-horizontal">
        <div class="form-group">
            <label for="area" style="padding:6px 0px 0px 10px" class="col-xs-2 control-label">
                区域</label><div class="col-xs-10">
                    <select class="form-control" id="area">
                        <option value=""></option>
                        <option value="旧白宫">7-13栋</option>
                        <option value="四合院">14-22栋</option>
                        <option value="北区女生宿舍">23-33栋</option>
                        <option value="新白宫">34-37栋</option>
                        <option value="西区宿舍">38-43栋</option>
                        <option value="玫瑰园1">44-46栋</option>
                        <option value="玫瑰园2">47-48栋</option>
                        <option value="其他">其他</option>
                    </select></div>
        </div>
        <div class="form-group">
            <label for="building" style="padding:6px 0px 0px 10px" class="col-xs-2 control-label">
                楼号</label><div class="col-xs-10">
                    <input type="text" class="form-control" id="building" placeholder="如果区域为其他，请填1" /></div>
        </div>
        <div class="form-group">
            <label for="dorm" style="padding:6px 0px 0px 10px" class="col-xs-2 control-label" style="padding-right: 0;">
                宿舍号</label><div class="col-xs-10">
                    <input type="text" class="form-control" id="dorm" /></div>
        </div>
        <div class="form-group">
            <label for="phone" style="padding:6px 0px 0px 10px" class="col-xs-2 control-label">
                电话</label><div class="col-xs-10">
                    <input type="text" class="form-control" id="phone" /></div>
        </div>
        <hr />
        <button id="bind" type="button" onclick="Submit()" class="btn btn-info btn-block btn-lg">
            确认绑定</button></form>
        <div id="tips" class="text-center text-danger">
        </div>
    </div>
    
</body>
</html>
